package design.prototype;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 深拷贝
 */
@NoArgsConstructor
@AllArgsConstructor
@Data
public class Cell2 implements Cloneable{
    private String name;
    private Cell2 cell2;
    public Cell2(String name) {
        this.name = name;
    }
    @Override
    protected Object clone() throws CloneNotSupportedException {
        Cell2 clone = (Cell2) super.clone();
        if(this.cell2!=null){
            clone.setCell2((Cell2) this.cell2.clone());
        }
        return clone;
    }

    public static void main(String[] args) throws CloneNotSupportedException {
        Cell2 cell2 = new Cell2("卵细胞", new Cell2("test"));
        //直接使用clone方法克隆对象
        Cell2 clone = (Cell2) cell2.clone();
        System.out.println(cell2.getCell2()==clone.getCell2());
    }

}
